package com.tbit.uqbike.quartz;

import com.tbit.uqbike.constant.SysConstant;
import com.tbit.uqbike.object.business.Point;
import com.tbit.uqbike.object.pojo.Geo;
import com.tbit.uqbike.object.pojo.ProhibitArea;
import com.tbit.uqbike.service.base.CalibrateService;
import com.tbit.uqbike.webmanager.dao.core.GeoDao;
import com.tbit.uqbike.webmanager.dao.core.ProhibitAreaDao;
import com.tbit.utils.GeoUtil;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author jing
 * @date 2021/3/109:12
 * @Description:
 */
@Component
public class PointQuartz {
    @Resource
    private GeoDao geoDao;
    @Resource
    private ProhibitAreaDao prohibitAreaDao;
    @Resource
    private CalibrateService calibrateService;

    public void calibrationPoint() {
        List<Geo> geos = geoDao.selectAll();
        for (Geo geo : geos) {
            List<Point> points = GeoUtil.getPoints(geo.getPoints());
            List<Point> pointCs = new ArrayList<>();
            for (Point point : points) {
                pointCs.add(calibrateService.commonCalibrate(point, SysConstant.ORIGINAL, SysConstant.GOOGLE));
            }
            geo.setPointsC(GeoUtil.getPointToString(pointCs));
            geoDao.updatePoiontsC(geo);
        }

        List<ProhibitArea> prohibitAreas = prohibitAreaDao.get();
        for (ProhibitArea prohibitArea : prohibitAreas) {
            List<Point> points = GeoUtil.getPoints(prohibitArea.getPoints());
            List<Point> pointCs = new ArrayList<>();
            for (Point point : points) {
                pointCs.add(calibrateService.commonCalibrate(point, SysConstant.ORIGINAL, SysConstant.GOOGLE));
            }
            prohibitArea.setPointsC(GeoUtil.getPointToString(pointCs));
            prohibitAreaDao.update(prohibitArea);
        }


    }

}
